package com.lczyfz.istep.modules.openstack.api.keystone;


import com.lczyfz.istep.modules.openstack.api.keystone.impl.CatalogAndEndpointImpl;
import com.lczyfz.istep.modules.openstack.api.keystone.impl.TokenManagementImpl;
import com.lczyfz.istep.modules.openstack.api.keystone.interfaces.CatalogAndEndpoint;
import com.lczyfz.istep.modules.openstack.api.keystone.interfaces.TokenManagement;

/**
 * keystone�������API
 * @author jm
 */
public class Keystone {

	private static volatile Keystone keystone;
	
	private CatalogAndEndpoint catalogService;
	
	private TokenManagement tokenService;
	
	public TokenManagement getTokenService() {
		return tokenService;
	}

	public void setTokenService(TokenManagement tokenService) {
		this.tokenService = tokenService;
	}

	private Keystone(){
		this.tokenService = new TokenManagementImpl();
		this.tokenService.login();
		this.setCatalogService(new CatalogAndEndpointImpl());
	}
	
	public static Keystone getInstance() {
		if (null == keystone) {
			synchronized (Keystone.class){
				if(null == keystone){
					keystone = new Keystone();
				}
			}
		}
		return keystone;
	}
	
	public static void main(String[] args){
		Keystone keystone = Keystone.getInstance();
		System.out.println(keystone.tokenService.login().getId());
	}

	public CatalogAndEndpoint getCatalogService() {
		return catalogService;
	}

	public void setCatalogService(CatalogAndEndpoint catalogService) {
		this.catalogService = catalogService;
	}
}
